package dev.tools.view.dialogs;

import dev.tools.Utils;
import dev.tools.view.menus.DialogMenuItem;

import javax.swing.*;
import java.awt.*;

/**
 * Created with IntelliJ IDEA.
 * User: Nuno
 * Date: 05-10-2013
 * Time: 18:45
 */
public class Dialog extends JDialog{
    protected final DialogMenuItem menuItem;
    protected final JPanel contentsPanel;
    protected final JPanel buttonsPanel;

    public Dialog(Frame owner){
        this(owner, new BorderLayout());
    }

    public Dialog(Frame owner, LayoutManager layoutManager) {
        super(owner);

        setTitle(Utils.camelToTitleCase(this, "CommandDialog"));
        setLayout(new BorderLayout());

        contentsPanel = new JPanel(layoutManager);
        menuItem = new DialogMenuItem(this);
        buttonsPanel = new JPanel();

        getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
        getContentPane().add(new JScrollPane(contentsPanel));
    }

    public JPanel getButtonsPanel() {
        return buttonsPanel;
    }

    protected JButton addButton(String text) {
        JButton button = new JButton(text);

        buttonsPanel.add(button);

        return button;
    }

    @Override
    public void pack() {
        super.pack();
        setLocationRelativeTo(getParent());
    }

    @Override
    public void setVisible(boolean b) {
        pack();
        super.setVisible(b);
    }

    protected JPanel getContentsPanel() {
        return contentsPanel;
    }

    public DialogMenuItem getMenuItem() {
        return menuItem;
    }
}
